
//
$(".main-box-title-selection a:first-child").mouseover(function(){
    $(this).siblings("span").css({"left":"0"})
})
$(".main-box-title-selection a:nth-child(2)").mouseover(function(){
    $(this).siblings("span").css({"left":"70px"})
})
// 购物车点击事件





// 立即执行函数
$(function(){
    // 判断是否登录
    let uid = localStorage.getItem("uid")
    // console.log(uid);
    
    indexLeft();
    function indexLeft(){
        $.ajax({
            type:"get",
            url:"http://jx.xuzhixiang.top/ap/api/productlist.php",
            data:{
                uid:uid,
                pagesize:1,
                pagenum:27,
            },
            success:function(res){
                // console.log(res.data);
                 let leftData = res.data;
                //  console.log(leftData);
                 //渲染数据 父级元素获取需要使用js
                 let bigPic =document.querySelector(".index-main-box-left");
                //  console.log(bigPic);
                 let bightml="";
                 leftData.forEach((item)=>{
                    // console.log(item.pimg);
                    bightml +=`
                   
                    <a href="detail.html" target="_blank" data-id="${item.pid}" class=
                    "data-shop-jump">
                        <img src="${item.pimg}" alt="" ">
                    </a>
                   
                    `
                });

                bigPic.innerHTML=bightml;
                
                // a 标签点击事件
                let indexBigpic=$(".data-shop-jump");
                // console.log(indexBigpic);
                indexBigpic.click(function(){
                    let sid=this.getAttribute("data-id");
                    console.log(sid)
                    localStorage.setItem("shopID",sid);
                })
               
            }
        })
    }
    indexRight();
    function indexRight(){
        $.ajax({
            type:"get",
            url:"http://jx.xuzhixiang.top/ap/api/productlist.php",
            data:{
                uid:uid,
                pagesize:7,
                pagenum:3,
            },
            success:function(res){
                // console.log(res.data);
                 let rightData = res.data;
                //  console.log(rightData);
                 //渲染数据 父级元素获取需要使用js
                 let rightlist =document.querySelector(".index-main-box-right");
                //  console.log(rightlist);
                 let righthtml="";
                 rightData.forEach((item)=>{
                    // console.log(item.pimg);
                    righthtml +=`
                   
                    <li class="main-box-right-data" >
                    <a href="detail.html" target="_blank" data-id="${item.pid}">
                        <div class="box-right-data-img">
                             <img src="${item.pimg}" alt="">
                        </div>
                        <h3 class="box-right-data-title">${item.pname}</h3>
                        <p class="box-right-data-decor">${item.pdesc}</p>
                        <p class="box-right-data-price">
                             <span>${item.pprice}</span>
                             <del><span>229元</span></del>
                        </p>
                    </a>
                 </li>
                   
                    `
                });
                rightlist.innerHTML=righthtml;

                // a 标签点击事件
                let indexArr = $("a");
                console.log(indexArr);
                for(let i=0;i<indexArr.length;i++){
                    indexArr[i].onclick=function(){
                        if(this.getAttribute("data-id")){
                            let sid=this.getAttribute("data-id");
                            console.log(sid)
                            localStorage.setItem("shopID",sid);
                        }
                    }
                }
            }
        })
    }

    // 轮播图数据渲染
    indexBanner()
    function indexBanner(){
        let banseleArr= document.querySelectorAll(".banner-up-seletion");
        let userID = localStorage.getItem("uid");

        for(let i=0;i<banseleArr.length;i++){
            banseleArr[i].onmouseover=function(){
                $.ajax({
                    type:"get",
                    url:"http://jx.xuzhixiang.top/ap/api/allproductlist.php",
                    data:{
                        uid:userID,
                        pagesize:5,
                        pagenum:i,
                    },
                    success:function(res){
                        console.log(res.data);
                        let banhidData = res.data;
                        let banhidStr = "";
                        let banhidBox = document.querySelectorAll(".index-banner-hidden");
                        console.log(banhidBox);
                        banhidData.forEach((item)=>{
                            banhidStr +=`
                            <li>
                                <a href="list.html">
                                    <div class="index-nav-hidden-img">
                                        <img src="${item.pimg}" alt="">
                                    </div>
                                    
                                    <h3>${item.pname}</h3>
                                    <p>${item.pprice}元</p>
                                </a>
                            </li>
                            `;
                        })
                        banhidBox[i].innerHTML=banhidStr;
                    }
                })
            }
        }
    }

})



 



